<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            position: relative;
            width: 600px;
            height: 400px;
            margin: 0 auto;
            border: 10px solid rgb(0, 0, 0);
            overflow: hidden;
        }

        .banner {
            position: absolute;
            top: 0;
            left: 0;
            width: 3600px;
        }

        .banner li {
            list-style: none;
            float: left;
            width: 600px;
            height: 100%;
        }

        .banner li img {
            width: 100%;
            height: 100%;
        }

        .left-btn,
        .right-btn {
            position: absolute;
            width: 50px;
            height: 100px;
            background-color: rgba(250, 61, 7, .3);
            top: 50%;
            margin-top: -50px;
            text-align: center;
            line-height: 100px;
            font-size: 30px;
            color: white;
        }

        .left-btn {
            left: 0;
        }

        .right-btn {
            right: 0;
        }

        .left-btn:hover,
        .right-btn:hover {
            background-color: rgba(250, 61, 7, 1);
            cursor: pointer;
        }

        .cir {
            position: absolute;
            width: 300px;
            left: 50%;
            margin-left: -150px;
            bottom: 30px;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: space-around;
            list-style: none;
        }

        .cir li {
            width: 20px;
            height: 20px;
            background: rgb(255, 7, 181);
            border-radius: 50%;
        }

        .cir li.active {
            background: rgba(250, 61, 7, 1)
        }
    </style>
</head>

<body>
    <div id="box" class="box">
        <ul id="banner" class="banner">
            <li><img src="images/photo_0003_2022-04-02_H3UDKF1H00AJ0003NOS.jpg" alt=""></li>
            <li><img src="images/photo_0003_2022-04-02_H3UDKF1I00AJ0003NOS.jpg" alt=""></li>
            <li><img src="images/photo_0003_2022-04-02_H3UDKF1J00AJ0003NOS.jpg" alt=""></li>
            <li><img src="images/photo_0003_2022-04-02_H3UDKF1K00AJ0003NOS.jpg" alt=""></li>
            <li><img src="images/photo_0003_2022-04-02_H3UDKF1L00AJ0003NOS.jpg" alt=""></li>
            <li><img src="images/photo_0003_2022-04-02_H3UDKF1H00AJ0003NOS.jpg" alt=""></li>
        </ul>
        <div id="left_btn" class="left-btn">&lt;</div>
        <div id="right_btn" class="right-btn">&gt;</div>
        <ul id="cir" class="cir">
            <li class="active"></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
    <script src="./js/jquery.min.js"></script>
    <script>
        $(function () {
            // 获取元素
            let $box = $("#box");
            let $banner = $("#banner");
            let $leftBtn = $("#left_btn");
            let $rightBtn = $("#right_btn")
            let $cirs = $("#cir li");

            // 一张图片的宽度
            let width = $box.width();
            // 前面添加$的只有元素需要添加 
            let idx = 0;
            // 总共多少张图片
            let len = $cirs.length;

            // 右按钮点击事件
            $rightBtn.click(function () {
                // idx改变
                idx++;
                $banner.animate({ left: -idx * width }, 1000, function () {
                    if (idx >= len) {
                        idx = 0;
                        $banner.css("left", 0);
                    }
                })
            })

            $leftBtn.click(function () {
                idx--;
                if (idx < 0) {
                    idx = len;
                    $banner.css("left", -len * width)
                    idx--;
                }

                $banner.animate({ left: -idx * width }, 1000, function () {
                })
            })


            $cirs.each(function (index, value) {
                $(value).click(function () {
                    idx = index;
                    $banner.animate({ left: -idx * width }, 1000, function () {
                    })
                })
            })
        })
    </script>
</body>

</html>